package com.dys.testjdk12;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @className: com.dys.testjdk12.StringTransform
 * @description: 它提供的函数作为输入提供给特定的String实例，并返回该函数返回的输出。
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/08 下午8:44
 */
public class StringTransform {
    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) {
        // testTransform();
        // testTransform2();
        streamApiMap();
    }

    /**
     * transform用法
     */
    private static void testTransform() {
        String str = "baidu";
        String transform = str.transform((s) -> "www." + s + ".com");
        System.out.println(transform);
    }

    /**
     * transform用法
     */
    private static void testTransform2() {
        List<String> list1 = List.of("Java", " Go", "Python", "JavaScript", "C++", "Python", "C# ");
        List<String> list2 = new ArrayList<>();
        list1.forEach(ele -> list2.add(ele.transform(String::strip)
                .transform(String::toUpperCase)
                .transform(e -> "Hello," + e)));
        list2.forEach(System.out::println);
    }

    /**
     * Stream流去处理
     */
    private static void streamApiMap() {
        List<String> list1 = List.of("Java", " Go", "Python", "JavaScript", "C++", "Python", "C# ");
        Stream<String> stringStream = list1.stream().map(element -> element.strip())
                .map(String::toUpperCase)
                .map(ele -> "转换成功," + ele);
        List<String> list2 = stringStream.collect(Collectors.toList());
        list2.forEach(System.out::println);
    }

}
